
#include "Spawnpoint.h"
#include "../../SGD Wrappers/CSGD_TextureManager.h"
#include "EntityManager.h"
#include "Enemy.h"
#include "EventSystem.h"

//Constructor
Spawnpoint::Spawnpoint(void)
{
	this->x						= 0.0f;
	this->y						= 0.0f;
	this->velocityX				= 0.0f;
	this->velocityY				= 0.0f;
	this->rotation				= 0.0f;
	this->collisionRadius		= 1.0f;
	this->isAlive				= true;
	this->entityType			= ENTITY_SPAWNPOINT;
	this->firstWaypoint			= nullptr;
	this->spawnTimer			= 0.0f;
	this->spawnCounter			= 0;
	this->textureID = CSGD_TextureManager::GetInstance()->LoadTexture(_T("../Resource/Graphics/PlaceholderImage.png"));
}


//Destructor
Spawnpoint::~Spawnpoint(void)
{
}


//Update
void Spawnpoint::Update(float dt)
{
	spawnTimer += dt;

	if (spawnTimer >= 2.0f)
	{
		spawnCounter++;
		spawnTimer = 0.0f;
		Entity* newEnemy = EntityManager::GetInstance()->CreateEntity(ENTITY_ENEMY,x,y);
		dynamic_cast<Enemy*>(newEnemy)->currentWaypoint = firstWaypoint;
	}

	if (spawnCounter >= 10)
	{
		EventSystem* eventSystem = EventSystem::GetInstance();
		eventSystem->SendEvent("SPAWNPOINT_IS_EMPTY",nullptr,nullptr,nullptr);
		isAlive = false;
	}
}


//Render
void Spawnpoint::Render()
{
	CSGD_TextureManager* TM = CSGD_TextureManager::GetInstance();
	RECT rect = {0, 0, 64, 64};
	POINT ptCenter = { (rect.right - rect.left) / 2, (rect.bottom - rect.top) / 2 };
	TM->Draw(textureID, (int)x - ptCenter.x, (int)y - ptCenter.y, 1.0f, 1.0f, &rect,
		(float)ptCenter.x, (float)ptCenter.y, rotation, D3DCOLOR_ARGB(255,255,255,255));

	TM->Draw(textureID, (int)x-3, (int)y-3, 0.1f, 0.1f, &rect, 32.0f, 32.0f, rotation, D3DCOLOR_ARGB(255,255,50,50));
}
